home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / BaseShp.cpp next >
Encoding:
Text File  |  1996-09-17  |  27.7 KB  |  1,007 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef UTILS_H
  19. #include "Utils.h"
  20. #endif
  21.  
  22. #ifndef CONSTANT_H
  23. #include "Constant.h"
  24. #endif
  25.  
  26. #ifndef DEFINES_K
  27. #include "Defines.k"
  28. #endif
  29.  
  30. #ifndef DRAWCONT_H
  31. #include "DrawCont.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWAPLEVT_H
  61. #include "FWAplEvt.h"
  62. #endif
  63.  
  64. #ifndef FWFRMING_H
  65. #include "FWFrming.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. #ifndef FWSELECT_H
  73. #include "FWSelect.h"
  74. #endif
  75.  
  76. #ifndef FWITERS_H
  77. #include "FWIters.h"
  78. #endif
  79.  
  80. #ifndef FWINTER_H
  81. #include "FWInter.h"
  82. #endif
  83.  
  84. #ifndef FWPRMISE_H
  85. #include "FWPrmise.h"
  86. #endif
  87.  
  88. #ifndef FWDSCOPR_H
  89. #include "FWDscOpr.h"
  90. #endif
  91.  
  92. #ifndef FWSEMTRM_H
  93. #include "FWSemTrm.h"
  94. #endif
  95.  
  96. // ----- OS Layer -----
  97.  
  98. #ifndef FWACQUIR_H
  99. #include "FWAcquir.h"
  100. #endif
  101.  
  102. #ifndef FWEVENT_H
  103. #include "FWEvent.h"
  104. #endif
  105.  
  106. #ifndef FWRECSHP_H
  107. #include "FWRecShp.h"
  108. #endif
  109.  
  110. #ifndef FWTXTBOX_H
  111. #include "FWTxtBox.h"
  112. #endif
  113.  
  114. #ifndef FWLINSHP_H
  115. #include "FWLinShp.h"
  116. #endif
  117.  
  118. #ifndef FWOVLSHP_H
  119. #include "FWOvlShp.h"
  120. #endif
  121.  
  122. #ifndef FWRRCSHP_H
  123. #include "FWRRcShp.h"
  124. #endif
  125.  
  126. #ifndef FWODGEOM_H
  127. #include "FWODGeom.h"
  128. #endif
  129.  
  130. #ifndef FWCFMRES_H
  131. #include "FWCFMRes.h"
  132. #endif
  133.  
  134. #ifndef FWRESACC_H
  135. #include "FWResAcc.h"
  136. #endif
  137.  
  138. #ifndef FWRESTYP_H
  139. #include "FWResTyp.h"
  140. #endif
  141.  
  142. // ----- Foundation Includes -----
  143.  
  144. #ifndef FWSTREAM_H
  145. #include "FWStream.h"
  146. #endif
  147.  
  148. #ifndef FWSOMENV_H
  149. #include "FWSOMEnv.h"
  150. #endif
  151.  
  152. // ----- OpenDoc Includes -----
  153.  
  154. #ifndef SOM_ODTransform_xh
  155. #include <Trnsform.xh>
  156. #endif
  157.  
  158. //========================================================================================
  159. // Runtime Information
  160. //========================================================================================
  161.  
  162. #ifdef FW_BUILD_MAC
  163. #pragma segment odfdrawshapes
  164. #endif
  165.  
  166. //========================================================================================
  167. // RunTime Info
  168. //========================================================================================
  169.  
  170. FW_DEFINE_AUTO(CBaseShape)
  171. FW_DEFINE_CLASS_M1(CBaseShape, FW_MScriptable)
  172.  
  173. const FW_ClassTypeConstant LBaseShape = FW_TYPE_CONSTANT('s','h','b','a');
  174. FW_REGISTER_ARCHIVABLE_CLASS(LBaseShape, CBaseShape, CBaseShape::Read, 0, 0, CBaseShape::Write)
  175.  
  176. //========================================================================================
  177. // globals
  178. //========================================================================================
  179.  
  180. FW_CRectShape* CBaseShape::gWorkingHandle = NULL;
  181. unsigned long CBaseShape::gShapeCount = 0;
  182.  
  183. // [KVV] Constructing gDefaultStyle and gDefaultInk like this causes
  184. //    problems because of order of initialization
  185. // const FW_CStyle gDefaultStyle = FW_kNormalStyle;
  186. // const FW_CInk gDefaultInk = FW_kNormalInk;
  187.  
  188. const FW_EStandardStyles gDefaultStyle = FW_kNormalStyle;
  189. const FW_EStandardInks gDefaultInk = FW_kNormalInk;
  190.  
  191. //========================================================================================
  192. // class CShapeCollection
  193. //========================================================================================
  194.  
  195. FW_DEFINE_AUTO(CShapeCollection)
  196.  
  197. //========================================================================================
  198. // class CShapeCollectionIterator
  199. //========================================================================================
  200.  
  201. FW_DEFINE_AUTO(CShapeCollectionIterator)
  202.  
  203. //========================================================================================
  204. // class CBaseShape
  205. //========================================================================================
  206.  
  207. //----------------------------------------------------------------------------------------
  208. // CBaseShape::CBaseShape
  209. //----------------------------------------------------------------------------------------
  210.  
  211. CBaseShape::CBaseShape(CDrawPart* drawPart, 
  212.                         short numberOfHandles, 
  213.                        unsigned short shapeType, 
  214.                        unsigned short renderVerb) :
  215.     FW_MScriptable(),
  216.     fDrawPart(drawPart),
  217.     fSelected(FALSE),
  218.     fNumberOfHandles(numberOfHandles),
  219.     fShapeType(shapeType),
  220.     fPublishLink(NULL),
  221.     fSubscribeLink(NULL),
  222.     fRenderVerb(renderVerb),
  223.     fFrameInk(gDefaultInk),
  224.     fFillInk(gDefaultInk),
  225.     fFrameStyle(gDefaultStyle),
  226.     fFillStyle(gDefaultStyle),
  227.     fPromised(0),
  228.     fExternalizationIndex(0),
  229.     fClipShape(NULL)
  230. {
  231.     InitStatic();
  232.     FW_END_CONSTRUCTOR
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. // CBaseShape::CBaseShape
  237. //----------------------------------------------------------------------------------------
  238.  
  239. CBaseShape::CBaseShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  240.     FW_MScriptable(),
  241.     fDrawPart(drawPart),
  242.     fPublishLink(NULL),
  243.     fSubscribeLink(NULL),
  244.     fSelected(FALSE),
  245.     fPromised(0),
  246.     fExternalizationIndex(0),
  247.     fClipShape(NULL)
  248. {
  249.     InitStatic();
  250.     
  251.     archive >> fShapeType;
  252.     archive >> fNumberOfHandles;
  253.         
  254.     archive >> fFrameInk;
  255.     archive >> fFillInk;
  256.     archive >> fFrameStyle;
  257.     archive >> fFillStyle;
  258.  
  259.     archive >> fRenderVerb;
  260.     FW_END_CONSTRUCTOR
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. // CBaseShape::InitStatic
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void CBaseShape::InitStatic()
  268. {
  269.     if (gShapeCount == 0)
  270.     {
  271.         CBaseShape::gWorkingHandle = FW_NEW(FW_CRectShape, (FW_kZeroRect, FW_kFill));
  272.         CBaseShape::gWorkingHandle->SetInk(FW_kInvertInk);
  273.     }
  274.     
  275.     CBaseShape::gShapeCount++;
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. // CBaseShape::~CBaseShape
  280. //----------------------------------------------------------------------------------------
  281.  
  282. CBaseShape::~CBaseShape()
  283. {
  284.     FW_START_DESTRUCTOR
  285.     FW_ASSERT(fPromised == 0);    // I should have resolved all my promises
  286.     
  287.     if (fClipShape)
  288.     {
  289.         FW_SOMEnvironment ev;
  290.         fClipShape->Release(ev);
  291.     }
  292.         
  293.     CBaseShape::gShapeCount--;
  294.     if (CBaseShape::gShapeCount == 0)
  295.         delete CBaseShape::gWorkingHandle;
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. // CBaseShape::Removed
  300. //----------------------------------------------------------------------------------------
  301.  
  302. void CBaseShape::Removed(Environment* ev)
  303. {
  304. FW_UNUSED(ev);
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // CBaseShape::Deleted
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void CBaseShape::Deleted(Environment* ev)
  312. {
  313. FW_UNUSED(ev);
  314. }
  315.  
  316. //----------------------------------------------------------------------------------------
  317. // CBaseShape::CheckPromise
  318. //----------------------------------------------------------------------------------------
  319.  
  320. void CBaseShape::CheckPromise(Environment* ev)
  321. {
  322.     
  323.     if (fPromised & FW_kClipboardStorage)
  324.         fDrawPart->GetDataInterchange(ev)->ResolveClipboardPromise(ev);
  325.     FW_ASSERT((fPromised & FW_kClipboardStorage) == 0);        // because CBaseShape::Promised should have been called
  326.  
  327. }
  328.  
  329. //----------------------------------------------------------------------------------------
  330. // CBaseShape::Promised
  331. //----------------------------------------------------------------------------------------
  332.  
  333. void CBaseShape::Promised(FW_StorageKinds storageKind, FW_Boolean state)
  334. {
  335.     if (state)
  336.         fPromised |= storageKind;
  337.     else
  338.         fPromised ^= fPromised & storageKind;
  339. }
  340.  
  341. //----------------------------------------------------------------------------------------
  342. // CBaseShape::TrackFeedback
  343. //----------------------------------------------------------------------------------------
  344.  
  345. void CBaseShape::TrackFeedback(Environment* ev,
  346.                                 ODFacet* facet,
  347.                                 FW_CGraphicContext& gc,
  348.                                 const FW_CPoint& anchorPoint, 
  349.                                 const FW_CPoint& currentPoint, 
  350.                                 FW_Boolean erase)
  351. {
  352.     if (!erase)
  353.         SetShapeGeometry(anchorPoint, currentPoint);
  354.  
  355.     RenderShape(ev, facet, gc);
  356. }
  357.  
  358. //----------------------------------------------------------------------------------------
  359. // CBaseShape::SelectShape
  360. //----------------------------------------------------------------------------------------
  361.  
  362. void CBaseShape::SelectShape(Environment* ev, FW_Boolean state)
  363. {
  364. FW_UNUSED(ev);
  365.     fSelected = state;
  366. }
  367.  
  368. //----------------------------------------------------------------------------------------
  369. // CBaseShape::ClearCache
  370. //----------------------------------------------------------------------------------------
  371.  
  372. void CBaseShape::ClearCache(Environment* ev)
  373. {
  374.     if (fClipShape)
  375.     {
  376.         fClipShape->Release(ev);
  377.         fClipShape = NULL;
  378.     }
  379. }
  380.  
  381. //----------------------------------------------------------------------------------------
  382. // CBaseShape::Invalidate
  383. //----------------------------------------------------------------------------------------
  384.  
  385. void CBaseShape::Invalidate(Environment* ev)
  386. {
  387.     fDrawPart->GetDrawContent()->RedrawShape(ev, this);
  388. }
  389.  
  390. //----------------------------------------------------------------------------------------
  391. // CBaseShape::RenderHandles
  392. //----------------------------------------------------------------------------------------
  393.  
  394. void CBaseShape::RenderHandles(FW_CGraphicContext& gc, FW_Fixed zoomFactor)
  395. {    
  396.     FW_Fixed penSize = CalcHandlePenSize(zoomFactor);
  397.     for (short i=1; i<=fNumberOfHandles; i++)
  398.     {
  399.         CalcHandle(i, CBaseShape::gWorkingHandle, penSize);    
  400.         CBaseShape::gWorkingHandle->Render(gc);
  401.     }
  402. }
  403.  
  404. //----------------------------------------------------------------------------------------
  405. // CBaseShape::InvalidateHandles
  406. //----------------------------------------------------------------------------------------
  407.  
  408. void CBaseShape::InvalidateHandles(Environment* ev, FW_CView* contentView, ODShape* workingShape, FW_Fixed penSize)
  409. {    
  410.     FW_CRect rect;
  411.     for (short i=1; i<=fNumberOfHandles; i++)
  412.     {
  413.         CalcHandle(i, rect, penSize);    
  414.         workingShape->SetRectangle(ev, rect);
  415.         contentView->Invalidate(ev, workingShape);
  416.     }
  417. }
  418.  
  419. //----------------------------------------------------------------------------------------
  420. // CBaseShape::CalcHandle
  421. //----------------------------------------------------------------------------------------
  422.  
  423. void CBaseShape::CalcHandle(short whichHandle, FW_CRectShape* handle, FW_Fixed penSize) const
  424. {
  425.     FW_CRect rect;
  426.     CalcHandle(whichHandle, rect, penSize);
  427.     handle->SetRectangle(rect);
  428. }
  429.  
  430. //----------------------------------------------------------------------------------------
  431. // CBaseShape::CalcHandle
  432. //----------------------------------------------------------------------------------------
  433.  
  434. void CBaseShape::CalcHandle(short whichHandle, FW_CRect& rect, FW_Fixed penSize) const
  435. {
  436.     FW_CPoint pt;
  437.     GetHandleCenter(whichHandle, pt);
  438.     rect.Set(pt.x - penSize, pt.y - penSize, pt.x + penSize, pt.y + penSize);
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. // CBaseShape::InSelectionRect
  443. //----------------------------------------------------------------------------------------
  444.  
  445. FW_Boolean CBaseShape::InSelectionRect(const FW_CRect& selectRect) const
  446. {
  447.     FW_CRect bounds = GetRectGeometry();
  448.     
  449.     FW_CRect temp(bounds);
  450.     temp.Intersection(selectRect);
  451.     
  452.     return bounds == temp;
  453. }
  454.  
  455. //----------------------------------------------------------------------------------------
  456. // CBaseShape::Flatten
  457. //----------------------------------------------------------------------------------------
  458.  
  459. void CBaseShape::Flatten(FW_CWritableStream& archive)
  460. {    
  461.     archive << fShapeType;
  462.     archive << fNumberOfHandles;
  463.     
  464.     archive << fFrameInk;
  465.     archive << fFillInk;
  466.     archive << fFrameStyle;
  467.     archive << fFillStyle;
  468.     
  469.     archive << fRenderVerb;
  470. }
  471.  
  472. //----------------------------------------------------------------------------------------
  473. // CBaseShape::MovedAfter
  474. //----------------------------------------------------------------------------------------
  475.  
  476. void CBaseShape::MovedAfter(Environment* ev, CBaseShape* shape)
  477. {
  478. FW_UNUSED(ev);
  479. FW_UNUSED(shape);
  480. }
  481.  
  482. //----------------------------------------------------------------------------------------
  483. // CBaseShape::MovedBefore
  484. //----------------------------------------------------------------------------------------
  485.  
  486. void CBaseShape::MovedBefore(Environment* ev, CBaseShape* shape)
  487. {
  488. FW_UNUSED(ev);
  489. FW_UNUSED(shape);
  490. }
  491.  
  492. //----------------------------------------------------------------------------------------
  493. // CBaseShape::MovedFirst
  494. //----------------------------------------------------------------------------------------
  495.  
  496. void CBaseShape::MovedFirst(Environment* ev)
  497. {
  498. FW_UNUSED(ev);
  499. }
  500.  
  501. //----------------------------------------------------------------------------------------
  502. // CBaseShape::MovedLast
  503. //----------------------------------------------------------------------------------------
  504.  
  505. void CBaseShape::MovedLast(Environment* ev)
  506. {
  507. FW_UNUSED(ev);
  508. }
  509.  
  510. //----------------------------------------------------------------------------------------
  511. // CBaseShape::RestoreShape
  512. //----------------------------------------------------------------------------------------
  513.  
  514. void CBaseShape::RestoreShape(Environment *ev)
  515. {
  516.     if(fShapeType == kGroupShape || fSubscribeLink == NULL)
  517.         fDrawPart->AddShapeToPart(ev, this);
  518. }
  519.  
  520. //----------------------------------------------------------------------------------------
  521. // CBaseShape::SetFrozen
  522. //----------------------------------------------------------------------------------------
  523.  
  524. FW_Boolean CBaseShape::SetFrozen(FW_Boolean state)
  525. {
  526. FW_UNUSED(state);
  527.     return FALSE;    // Means I don't care
  528. }
  529.  
  530. //----------------------------------------------------------------------------------------
  531. // CBaseShape::IsFrozen
  532. //----------------------------------------------------------------------------------------
  533.  
  534. FW_Boolean CBaseShape::IsFrozen() const
  535. {
  536.     return FALSE;
  537. }
  538.  
  539. //----------------------------------------------------------------------------------------
  540. // CBaseShape::GetPenSize
  541. //----------------------------------------------------------------------------------------
  542.  
  543. FW_Fixed CBaseShape::GetPenSize() const
  544. {
  545.     return HasFrameStyle() ? fFrameStyle.GetPenSize() : FW_kFixed0;
  546. }
  547.  
  548. //----------------------------------------------------------------------------------------
  549. // CBaseShape::GetColor
  550. //----------------------------------------------------------------------------------------
  551. void CBaseShape::GetColor(FW_Boolean fill, FW_CColor& color)
  552. {
  553.     if (fill)
  554.         fFillInk.GetForeColor(color);
  555.     else
  556.         fFrameInk.GetForeColor(color);
  557. }
  558.  
  559. //----------------------------------------------------------------------------------------
  560. // CBaseShape::GetPattern
  561. //----------------------------------------------------------------------------------------
  562. FW_CPattern CBaseShape::GetPattern(FW_Boolean fill)
  563. {
  564.     if (fill)
  565.         return fFillStyle.GetPattern();
  566.     else
  567.         return fFrameStyle.GetPattern();
  568. }
  569.  
  570. //----------------------------------------------------------------------------------------
  571. // CBaseShape::UnshareInk
  572. //----------------------------------------------------------------------------------------
  573.  
  574. FW_CInk CBaseShape::UnshareInk(const FW_CInk& ink) const
  575. {
  576. //    Do not use the following syntax. It looks like the life time of temporaries
  577. //    is wrong causing a bad refcounting problem
  578. //    return (ink->GetRefCount() > 1) ? ink->Copy() : ink;
  579.  
  580.     if (ink.GetRefCount() > 1)
  581.         return ink.Copy();
  582.     else
  583.         return ink;
  584. }
  585.  
  586. //----------------------------------------------------------------------------------------
  587. // CBaseShape::UnshareStyle
  588. //----------------------------------------------------------------------------------------
  589.  
  590. FW_CStyle CBaseShape::UnshareStyle(const FW_CStyle& style) const
  591. {
  592. //    Do not use the following syntax. It looks like the life time of temporaries
  593. //    is wrong causing a bad refcounting problem
  594. //    return (style->GetRefCount() > 1) ? style->Copy() : style;
  595.  
  596.     if (style.GetRefCount() > 1)
  597.         return style.Copy();
  598.     else
  599.         return style;
  600. }
  601.  
  602. //----------------------------------------------------------------------------------------
  603. // CBaseShape::ChangeFrameColor
  604. //----------------------------------------------------------------------------------------
  605.  
  606. void CBaseShape::ChangeFrameColor(Environment* ev, const FW_CColor& color)
  607. {
  608.     if (HasFrameStyle())
  609.     {
  610.         CheckPromise(ev);
  611.         
  612.         fFrameInk = UnshareInk(fFrameInk);
  613.         fFrameInk.SetForeColor(color);
  614.     }
  615. }
  616.  
  617. //----------------------------------------------------------------------------------------
  618. // CBaseShape::ChangeFramePattern
  619. //----------------------------------------------------------------------------------------
  620.  
  621. void CBaseShape::ChangeFramePattern(Environment* ev, const FW_CPattern& pattern)
  622. {
  623.     if (HasFrameStyle())
  624.     {
  625.         CheckPromise(ev);
  626.         
  627.         fFrameStyle = UnshareStyle(fFrameStyle);
  628.         fFrameStyle.SetPattern(pattern);
  629.     }
  630. }
  631.  
  632. //----------------------------------------------------------------------------------------
  633. // CBaseShape::ChangeFillColor
  634. //----------------------------------------------------------------------------------------
  635.  
  636. void CBaseShape::ChangeFillColor(Environment* ev, const FW_CColor& color)
  637. {
  638.     if (HasFillStyle())
  639.     {
  640.         CheckPromise(ev);
  641.         
  642.         fFillInk = UnshareInk(fFillInk);
  643.         fFillInk.SetForeColor(color);
  644.     }
  645. }
  646.  
  647. //----------------------------------------------------------------------------------------
  648. // CBaseShape::ChangeFillPattern
  649. //----------------------------------------------------------------------------------------
  650.  
  651. void CBaseShape::ChangeFillPattern(Environment* ev, const FW_CPattern& pattern)
  652. {
  653.     if (HasFillStyle())
  654.     {
  655.         CheckPromise(ev);
  656.         
  657.         fFillStyle = UnshareStyle(fFillStyle);
  658.         fFillStyle.SetPattern(pattern);
  659.     }
  660. }
  661.  
  662. //----------------------------------------------------------------------------------------
  663. // CBaseShape::ChangePenSize
  664. //----------------------------------------------------------------------------------------
  665.  
  666. void CBaseShape::ChangePenSize(Environment* ev, FW_Fixed newPenSize)
  667. {
  668.     if (HasFrameStyle())
  669.     {
  670.         CheckPromise(ev);
  671.         
  672.         ClearCache(ev);
  673.         
  674.         fFrameStyle = UnshareStyle(fFrameStyle);
  675.         fFrameStyle.SetPenSize(newPenSize);
  676.     }
  677. }
  678.  
  679. //----------------------------------------------------------------------------------------
  680. // CBaseShape::SetSubscribeLink
  681. //----------------------------------------------------------------------------------------
  682.  
  683. void CBaseShape::SetSubscribeLink(Environment* ev, CDrawSubscribeLink *subscribeLink)
  684. {
  685. FW_UNUSED(ev);
  686.  
  687.     fSubscribeLink = subscribeLink;
  688. }
  689.  
  690. //----------------------------------------------------------------------------------------
  691. // CBaseShape::SetPublishLink
  692. //----------------------------------------------------------------------------------------
  693.  
  694. void CBaseShape::SetPublishLink(Environment* ev, CDrawPublishLink *publishLink)
  695. {
  696. FW_UNUSED(ev);
  697.  
  698.     fPublishLink = publishLink;
  699. }
  700.  
  701. //----------------------------------------------------------------------------------------
  702. // CBaseShape::AdjustRectForPenSize
  703. //----------------------------------------------------------------------------------------
  704.  
  705. void CBaseShape::AdjustRectForPenSize(FW_CRect& rect, FW_Fixed penSize) const
  706. {
  707.     FW_Fixed half = FW_Half(penSize);
  708.     rect.Inset(-half, -half);
  709. }
  710.  
  711. //----------------------------------------------------------------------------------------
  712. // CBaseShape::ChangeRenderVerb
  713. //----------------------------------------------------------------------------------------
  714.  
  715. void CBaseShape::ChangeRenderVerb(Environment* ev, unsigned short renderVerb)
  716. {
  717.     CheckPromise(ev);
  718.     
  719.     ClearCache(ev);
  720.     fRenderVerb = renderVerb;
  721. }
  722.  
  723. //----------------------------------------------------------------------------------------
  724. // CBaseShape::GetObjectClass
  725. //----------------------------------------------------------------------------------------
  726.  
  727. ODDescType CBaseShape::GetObjectClass() const
  728. {
  729.     return kShapeClass;
  730. }
  731.  
  732. //----------------------------------------------------------------------------------------
  733. // CBaseShape::HasProperty
  734. //----------------------------------------------------------------------------------------
  735.  
  736. FW_Boolean CBaseShape::HasProperty(ODDescType whichProperty) const
  737. {
  738.     FW_Boolean hasProperty;
  739.     
  740.     switch (whichProperty)
  741.     {
  742.         case pColor:
  743.         case pPosition:
  744.         case pIndex:
  745.             hasProperty = TRUE;
  746.             break;
  747.         
  748.         default:
  749.             hasProperty = FW_MScriptable::HasProperty(whichProperty);
  750.             break;
  751.     }
  752.     return hasProperty;
  753. }
  754.  
  755. //----------------------------------------------------------------------------------------
  756. // CBaseShape::GetProperty
  757. //----------------------------------------------------------------------------------------
  758.  
  759. FW_Boolean CBaseShape::GetProperty(Environment* ev,
  760.                                 FW_CPart* part,
  761.                                 FW_CDesc& propertyValue, 
  762.                                 ODDescType whichProperty,
  763.                                 ODDescType desiredType) const
  764. {
  765.     FW_Boolean result = TRUE;
  766.     
  767.     switch (whichProperty)
  768.     {            
  769.         case pColor:
  770.             {
  771.                 FW_CColor color = fFillInk.GetForeColor();
  772.                 propertyValue << color;
  773.             }
  774.             break;
  775.                         
  776.         case pPosition:
  777.             propertyValue << GetRectGeometry().TopLeft().AsPlatformPoint();
  778.             break;
  779.                         
  780.         default:
  781.             result = FW_MScriptable::GetProperty(ev, part, propertyValue, whichProperty, desiredType);
  782.             break;
  783.     }
  784.     
  785.     return result;
  786. }
  787.  
  788. //----------------------------------------------------------------------------------------
  789. // CBaseShape::SetProperty
  790. //----------------------------------------------------------------------------------------
  791.  
  792. void CBaseShape::SetProperty(Environment* ev,
  793.                             FW_CPart* part,
  794.                             FW_CDesc& propertyValue, 
  795.                             ODDescType whichProperty)
  796. {    
  797.     switch (whichProperty)
  798.     {
  799.         case pColor:
  800.             {
  801.                 if (HasFillStyle())
  802.                 {
  803.                     FW_CColor newColor;
  804.                     propertyValue >> newColor;
  805.         
  806.                     FW_CColor oldColor;
  807.                     GetColor(TRUE, oldColor);
  808.                     
  809.                     if (newColor != oldColor)
  810.                     {
  811.                         ChangeFillColor(ev, newColor);
  812.                         Invalidate(ev);
  813.                     }
  814.                 }
  815.             }
  816.             break;
  817.             
  818.         case pPosition:
  819.             {
  820.                 FW_CPoint     newPosition;
  821.                 FW_CRect    bounds = GetRectGeometry();
  822.                 
  823.                 propertyValue >> newPosition;
  824.                 
  825.                 Invalidate(ev);    // inval the old location            
  826.                 OffsetShape(ev, newPosition.x - bounds.left, newPosition.y - bounds.top);
  827.                 Invalidate(ev);    // inval the new location    
  828.             }
  829.             break;
  830.             
  831.         default:
  832.             FW_MScriptable::SetProperty(ev, part, propertyValue, whichProperty);
  833.             break;
  834.     }
  835. }
  836.  
  837. //----------------------------------------------------------------------------------------
  838. // CBaseShape::GetUndoStrings
  839. //----------------------------------------------------------------------------------------
  840.  
  841. void CBaseShape::GetUndoStrings(Environment* ev,
  842.                                 FW_CPart* part,
  843.                                 ODDescType whichProperty,
  844.                                 FW_CString& undoString,
  845.                                 FW_CString& redoString) const
  846. {
  847.     if (whichProperty == pColor)
  848.     {
  849.         FW_PSharedLibraryResourceFile resFile(ev);
  850.         ::FW_LoadStringByID(ev, resFile, kDrawUndoStrings, FW_kMultiStringRes, kUndoFillColorMsg, undoString);
  851.         ::FW_LoadStringByID(ev, resFile, kDrawUndoStrings, FW_kMultiStringRes, kRedoFillColorMsg, redoString);
  852.     }
  853.     else
  854.         FW_MScriptable::GetUndoStrings(ev, part, whichProperty, undoString, redoString);
  855. }
  856.  
  857. //----------------------------------------------------------------------------------------
  858. // CBaseShape::Read
  859. //----------------------------------------------------------------------------------------
  860.  
  861. void* CBaseShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  862. {
  863. FW_UNUSED(stream);
  864. FW_UNUSED(type);
  865.     FW_DEBUG_MESSAGE("CBaseShape::Read should never be called");
  866.     return NULL;
  867. }
  868.  
  869. //----------------------------------------------------------------------------------------
  870. // CBaseShape::Write
  871. //----------------------------------------------------------------------------------------
  872.  
  873. void CBaseShape::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  874. {
  875. FW_UNUSED(type);
  876.      ((CBaseShape*)object)->Flatten(stream);
  877. }
  878.  
  879. //----------------------------------------------------------------------------------------
  880. // CBaseShape::GetUpdateBox
  881. //----------------------------------------------------------------------------------------
  882.  
  883. void CBaseShape::GetUpdateBox(Environment* ev, ODShape* updateBox) const
  884. {
  885.     FW_CRect bounds = GetRectGeometry();    
  886.  
  887.     const FW_Fixed fxMargin = FW_IntToFixed(3);
  888.  
  889.     bounds.left        -= fxMargin;
  890.     bounds.top        -= fxMargin;
  891.     bounds.right    += fxMargin;
  892.     bounds.bottom    += fxMargin;
  893.  
  894.     ODRect odBounds = bounds;
  895.     updateBox->SetRectangle(ev, &odBounds);
  896. }
  897.  
  898. //----------------------------------------------------------------------------------------
  899. // CBaseShape::GetUpdateBox
  900. //----------------------------------------------------------------------------------------
  901.  
  902. void CBaseShape::GetUpdateBox(FW_CRect& updateBox) const
  903. {
  904.     updateBox = GetRectGeometry();
  905.  
  906.     const FW_Fixed fxMargin = FW_IntToFixed(3);
  907.  
  908.     updateBox.left        -= fxMargin;
  909.     updateBox.top        -= fxMargin;
  910.     updateBox.right        += fxMargin;
  911.     updateBox.bottom    += fxMargin;
  912. }
  913.  
  914. //----------------------------------------------------------------------------------------
  915. // CBaseShape::GetDragRect
  916. //----------------------------------------------------------------------------------------
  917.  
  918. void CBaseShape::GetDragRect(FW_CRect& dragRect) const
  919. {
  920.     dragRect = GetRectGeometry();
  921.     AdjustRectForPenSize(dragRect, GetPenSize());
  922. }
  923.  
  924. //----------------------------------------------------------------------------------------
  925. // CBaseShape::GetResizeStyle
  926. //----------------------------------------------------------------------------------------
  927.  
  928. FW_CStyle CBaseShape::GetResizeStyle() const
  929. {
  930.     FW_CStyle resizeStyle(GetPenSize(), FW_kGrayPat);
  931.     return resizeStyle;
  932. }
  933.  
  934. //----------------------------------------------------------------------------------------
  935. // CBaseShape::SubtractToWorkingClip
  936. //----------------------------------------------------------------------------------------
  937. //    ATTENTION: workingClip is in Content coordinates. tempShape is just a working shape. It is
  938. //    allocated by CDrawFrame::ClipEmbeddedFacets so I don't have to allocate one everytime.
  939.  
  940. void CBaseShape::SubtractToWorkingClip(Environment *ev, 
  941.                                         CDrawFacetClipper* facetClipper, 
  942.                                         ODFacet* containingFacet, 
  943.                                         ODShape* workingClip, 
  944.                                         ODShape* tempShape,
  945.                                         ODShape* limitShape)
  946. {
  947. FW_UNUSED(facetClipper);
  948. FW_UNUSED(containingFacet);
  949. FW_UNUSED(tempShape);
  950. FW_UNUSED(limitShape);
  951.  
  952.     FW_CAcquiredODShape clipShape = AcquireClipShape(ev);
  953.     workingClip->Subtract(ev, clipShape);
  954. }
  955.  
  956. //----------------------------------------------------------------------------------------
  957. // CBaseShape::WhichHandle
  958. //----------------------------------------------------------------------------------------
  959.  
  960. short CBaseShape::WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse, FW_Fixed zoomFactor) const
  961. {
  962.     FW_Fixed penSize = CalcHandlePenSize(zoomFactor);
  963.     for (short i=1; i<=fNumberOfHandles; i++)
  964.     {
  965.         CalcHandle(i, CBaseShape::gWorkingHandle, penSize);
  966.         if (CBaseShape::gWorkingHandle->HitTest(gc, mouse, FW_kFixed0))
  967.             return i;
  968.     }
  969.         
  970.     return 0;
  971. }
  972.  
  973. //----------------------------------------------------------------------------------------
  974. // CBaseShape::IsInLinkDestination
  975. //----------------------------------------------------------------------------------------
  976.  
  977. FW_Boolean CBaseShape::IsInLinkDestination(Environment* ev)
  978. {
  979. FW_UNUSED(ev);
  980.     return IsSubscribed();
  981. }
  982.  
  983. //----------------------------------------------------------------------------------------
  984. // CBaseShape::AcquireClipShape
  985. //----------------------------------------------------------------------------------------
  986.  
  987. ODShape* CBaseShape::AcquireClipShape(Environment* ev)
  988. {
  989.     if (fClipShape == NULL)
  990.         fClipShape = CalcClipShape(ev);
  991.     
  992.     fClipShape->Acquire(ev);
  993.     return fClipShape;
  994. }
  995.  
  996. //----------------------------------------------------------------------------------------
  997. // CBaseShape::MakePurgeable
  998. //----------------------------------------------------------------------------------------
  999.  
  1000. void CBaseShape::MakePurgeable(Environment* ev, CDrawFrame* drawFrame, const FW_CRect& bounds)
  1001. {
  1002. FW_UNUSED(ev);
  1003. FW_UNUSED(drawFrame);
  1004. FW_UNUSED(bounds);
  1005.     // Does nothing (see CProxyShape::MakePurgeable)
  1006. }
  1007.